$(function(){
	//设置喜欢页面ul高度
	var wh=$(window).height()-$(".portrait_box").height()-$(".weui-tabbar").height()-$(".weui-navbar").height()-45
	$('.weui-mark,.weui-tab__content').css('height',wh)
    initLeft();

	var num=1;
    var swiperv = new Swiper('.swiper-container-h', {
        direction: 'vertical',
        on:{slideChangeTransitionEnd: function() {
             var obj=$('.swiper-container-h>.swiper-wrapper>.swiper-slide .hidenews .xyg_value')[this.activeIndex];
            var id=obj.dataset.id;
            var num=obj.dataset.num;
             var d=$('.swiper-container-h>.swiper-wrapper>.swiper-slide .hidenews')[this.activeIndex].innerHTML;
            var news='<div class="xinxin x'+id+'"><img onclick="addLove(\''+id+'\')" src="/mobile/img/aixin2.png"/><div class="xinnum">'+num+'</div></div>';
                $("#tab1 .use_show").html(news);
            $("#tab1 .role_per").html(d);
                //上下切换监听事件，下面可调用接口
                if(num==1){
                    num=2;
                }else{
                    num=1;
                }
                if(isIsLastPage){
                    $.toast("已经是最后一个了！","text");
                }else{
                    addUser(num);
                }
                initLeft();
                for(var i in swiperh){
                    if(swiperv.realIndex==i){
                        swiperh[i].slideTo(0, 500, true);
                    }
             }
        }
        }
    });
    var swiperh =null;
    function initLeft() {
        //swiper切换
        swiperh = new Swiper('.swiper-container-v', { //左右切换
            pagination: {
                el: '.swiper-pagination-v',
                clickable: true,
            },
            spaceBetween: 50,
            autoplay: {
                delay: 3000,
                disableOnInteraction: false
            },
            paginationClickable: true,
        })
    }
    var pageStart = 2;
    var limit = 1;
    var isIsLastPage=false;
	function addUser(num) {
        pageStart++;
        $.post("/phone/userList", {
            limit: limit,
            page: pageStart,
            memberId:memberId
        }, function (resultInfo) {
            if(resultInfo.isIsLastPage){
                isIsLastPage=true;
            }
            if (resultInfo.data != null && resultInfo.data.length > 0) {
                for (var i = 0; i < resultInfo.data.length; i++) {
                    var item = resultInfo.data[i];
                    var news='<div class="xyg_value" data-id="'+item.id+'" data-num="'+item.attentNum+'">'+
                        '<div class="role_box">'+
                        '<div class="photo">'+
                        '<img src="'+item.headImage+'"></div>'+
                        '<div class="addressandother">'+
                        '<p>'+
                        '<span class="name overhidden">'+item.nickName+'</span>';
                    if(item.sex=="1"){
                        //男
                        news+='<img src="/mobile/img/man.png">';
                    }else{
                        news+='<img src="/mobile/img/women.png">';
                    }
                    var introduct=item.introduct;
                    if(introduct==null||introduct==""){
                        introduct="未填";
                    }
                    var want=item.want;
                    if(want==null||want==""){
                        want="未填";
                    }
                    var memberHeight=item.memberHeight;
                    if(memberHeight==null||memberHeight==""){
                        memberHeight="未填";
                    }
                    var schoolName=item.schoolName;
                    if(schoolName==null||schoolName==""){
                        schoolName="未填";
                    }
                    news+='<span>'+item.age+'</span>'+
                        '<span>'+item.star+'</span></p>'+
                        '<p>长居：'+
                        '<span>'+item.useAddress+'</span>| 故居：'+
                        '<span>'+item.comeAddress+'</span></p>'+
                        '</div>'+
                        '</div>'+
                        '<div class="role_feature">'+
                        '<ul>'+
                        '<li>'+
                        '<h3>TA的描述</h3>'+
                        '<p class="overhidden">'+
                        '<i class="icon">'+
                        '<em></em>'+
                        '</i>'+
                        '<span>'+introduct+'</span></p>'+
                        '</li>'+
                        '<li>'+
                        '<h3>TA的期待</h3>'+
                        '<p class="overhidden">'+
                        '<i class="icon">'+
                        '<em></em>'+
                        '</i>'+
                        '<span>'+want+'</span></p>'+
                        '</li>'+
                        '<li>'+
                        '<h3>TA的信息</h3>'+
                        '<p class="overhidden">'+
                        '<i class="icon">'+
                        '<em></em>'+
                        '</i>'+
                        '<span>'+memberHeight+'</span></p>'+
                        '<p class="overhidden">'+
                        '<i class="icon">'+
                        '<em></em>'+
                        '</i>'+
                        '<span>'+schoolName+'</span></p>'+
                        '</li>'+
                        '<li>'+
                        '<h3>TA的标签</h3>'+
                        '<p>'+
                        '<i class="icon">'+
                        '<em></em>'+
                        '</i>'+
                        '<span class="tab_box">';
                        if(item.memberTagList!=null&&item.memberTagList.length>0){
                            for(var i=0;i<item.memberTagList.length;i++){
                                news+='<b>'+item.memberTagList[i]+'</b>';
                            }
                        }
                    news+='</span>'+
                        '</p>'+
                        '</li>'+
                        '<li>'+
                        '<h3>可聊话题</h3>'+
                        '<p>'+
                        '<i class="icon">'+
                        '<em></em>'+
                        '</i>';
                        if(item.likeThemeList!=null&&item.likeThemeList.length>0){
                            for(var i=0;i<item.likeThemeList.length;i++){
                                news+='<b>'+item.likeThemeList[i]+'</b>';
                            }
                        }
                    news+='</span>'+
                        '</p>'+
                        '</li>'+
                        '<li>'+
                        '<h3>日常运动</h3>'+
                        '<p>'+
                        '<i class="icon">'+
                        '<em></em>'+
                        '</i>'+
                        '<span class="tab_box">';
                    if(item.likeSportList!=null&&item.likeSportList.length>0){
                        for(var i=0;i<item.likeSportList.length;i++){
                            news+='<b>'+item.likeSportList[i]+'</b>';
                        }
                    }
                    news+='</span>'+
                        '</p>'+
                        '</li>'+
                        '<li>'+
                        '<h3>音乐偏好</h3>'+
                        '<p>'+
                        '<i class="icon">'+
                        '<em></em>'+
                        '</i>'+
                        '<span class="tab_box">';
                    if(item.likeMusicList!=null&&item.likeMusicList.length>0){
                        for(var i=0;i<item.likeMusicList.length;i++){
                            news+='<b>'+item.likeMusicList[i]+'</b>';
                        }
                    }
                    news+='</span>'+
                        '</p>'+
                        '</li>'+
                        '</ul>'+
                        '<a href="javascript:addStar(\''+item.id+'\');;" class="getAdd">发起邀请</a></div>'+
                        '</div>';

                    var s='<div class="swiper-slide">'+
                        '<div class="swiper-container swiper-container-v">'+
                        '<div class="swiper-wrapper">';
                        if(item.picOne!=null&&item.picOne!=""){
                            s+='<div class="swiper-slide">'+
                            '<div class="role_img">'+
                            '<img src="'+item.picOne+'"></div>'+
                            '</div>'
                        }
                    if(item.picTwo!=null&&item.picTwo!=""){
                        s+='<div class="swiper-slide">'+
                            '<div class="role_img">'+
                            '<img src="'+item.picTwo+'"></div>'+
                            '</div>'
                    }
                    if(item.picThree!=null&&item.picThree!=""){
                        s+='<div class="swiper-slide">'+
                            '<div class="role_img">'+
                            '<img src="'+item.picThree+'"></div>'+
                            '</div>'
                    }
                    if(item.picFour!=null&&item.picFour!=""){
                        s+='<div class="swiper-slide">'+
                            '<div class="role_img">'+
                            '<img src="'+item.picFour+'"></div>'+
                            '</div>'
                    }
                    if(item.picFive!=null&&item.picFive!=""){
                        s+='<div class="swiper-slide">'+
                            '<div class="role_img">'+
                            '<img src="'+item.picFive+'"></div>'+
                            '</div>'
                    }

                    s+='</div>'+
                        '<div class="swiper-pagination swiper-pagination-v"></div>'+
                        '</div>'+
                        '<div class="hidenews" style="display: none;">'+news+'</div>'+
                        '</div>';
                    swiperv.appendSlide(s);
                }
            }
        }, "json");

    }



//点击弹出详情
$('.role_per').click(function() {
	for(var i in swiperh){
		if(swiperv.realIndex==i){
			swiperh[i].autoplay.stop();
			
		}
	}
	$(".mask").fadeIn(50)
	$('.getAdd').fadeIn()
	$(this).css("width", "100%")
	$(this).animate({
		top: '5.5rem'
	}, 200);
});
//关闭详情
function role_per_hide(){
	for(var i in swiperh){
		if(swiperv.realIndex==i){
			swiperh[i].autoplay.start();
			
		}
	}
	$('.getAdd').fadeOut(50)
	
	$('.role_per').css({
		"width": "90vw"
	})
	
		var top_h = $('.weui-tabbar').offset().top - 79;
		$('.role_per').animate({
			top: top_h
		}, 200);
	
}

//关闭弹窗
$('.mask').click(function() {
	$(this).fadeOut(50)
	role_per_hide()
	system_messages_hide()
})
//顶部tab切换

   $('.weui-navbar__item').on('click', function () {
        $(this).addClass('tab-pink').siblings('.tab-pink').removeClass('tab-pink');
        $(jQuery(this).attr("href")).show().siblings('.weui-tab__content').hide();
    });

//标签多选
$(".weui-form").find("label") .click(function(){
	if($(this).hasClass("selected")==false){
		$(this).addClass("selected");
	}else{
		$(this).removeClass("selected");	
	}
})
})
//弹出系统消息function
function system_messages(){
    $(".mask").fadeIn(50)
    $('.system_messages').animate({
        bottom: '-5rem'
    }, 200);
}
function system_messages_hide(){

    $('.system_messages').animate({
        bottom: '-100%'
    }, 200);
}